package com.wh.wisdomsite.xbox.core;


import com.alibaba.fastjson.JSONObject;
import com.wh.wisdomsite.xbox.common.AbstractXboxRequest;
import com.wh.wisdomsite.xbox.common.Constants;
import com.wh.wisdomsite.xbox.core.session.impl.SimpleSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * Session缓存容器
 * @Package com.wh.wisdomsite.xbox.core
 * @author 谢泽鹏
 * @date 2014年10月8日 下午4:02:14
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2014
 * @version V1.0
 */
public class SessionConst {

    private static final Log logger = LogFactory.getLog(SessionConst.class);

    /**
     * 获取SessionUser
     * @param in
     * @return
     */
    public static SessionUser getSessionUser(AbstractXboxRequest in) {
        try{
            SimpleSession simpleSession = (SimpleSession) in.getXboxRequestContext().getSession();
            if(null != simpleSession){
                SessionUser sessionUser = JSONObject.toJavaObject((JSONObject) simpleSession.getAttribute(Constants.SESSION_USER), SessionUser.class);
                return sessionUser;
            }
        } catch (Exception e){
            e.printStackTrace();
            logger.error("getSessionUser-->>Exception " + e.getMessage());
        }
            return null;
    }




    /**
     * 移除SessionUser
     * @param in
     */
    public static void removeSessionUser(AbstractXboxRequest in){
        in.getXboxRequestContext().removeSession();
    }

    /**
     * 移除短信|语音验证码
     * @param in
     * @param sessionId (短信|语音)标识
     * @return
     */
    public static void removeSmsCode(AbstractXboxRequest in, String sessionId){
        in.getXboxRequestContext().removeOtherSesssion(sessionId);
    }


}
